package main

import (
	"fmt"
)

func main() {
	c := make(chan int, 1000)
	go func() {
		defer fmt.Println("goroutine is finshed")
		fmt.Println("goutine is working")
		for i := 0; i < 1000; i++ {
			c <- i
			fmt.Printf("goroutine 正在写入数据，i = %d\n", i)
		}
	}()

	//阻塞等待
	for i := 0; i < 5; i++ {
		num := <-c
		fmt.Printf("main 正在读取数据，num = %d\n", num)
	}
	//time.Sleep(time.Second)
	fmt.Println("MAIN Goroutine is finshed")

}
